const mysql = require("mysql");
const path = require("path");
const log = require(path.resolve(__dirname, '../../../tool/log/log'));
class DB{
    constructor(config = {}){
        // create mysql pool
        this.db = mysql.createPool(config);

    }
    query(sql = '', cb = () => {}){
        this.db.getConnection((err, conn) => {
            if(err){
                log.error.error(err);
                cb(err);
            } else {
                conn.query(sql, (err, res, fd) => {
                    if(err){
                        log.error.error(sql);
                        log.error.error(err);
                        cb(err);
                    } else {
                        cb(null, res, fd);
                    }
                })
            }
        });
    }
    
}

module.exports = DB;
